package com.lqk.channel.socket.datagramchannel;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.charset.StandardCharsets;

public class DatagramChannelDemo1 {
    //发送的实现
    public static void main(String[] args) throws Exception {
        //打开 DatagramChannel
        DatagramChannel sendChannel = DatagramChannel.open();
        InetSocketAddress sendAddress=new InetSocketAddress("127.0.0.1",9999);

        //发送
        while (true){
            ByteBuffer sendBuffer=ByteBuffer.wrap("发送lqk".getBytes(StandardCharsets.UTF_8));
            sendChannel.send(sendBuffer,sendAddress);
            System.out.println("发送完毕！");

            Thread.sleep(1000);
        }
    }


}
